***************************************************************************************************
********************* Lasse Laustsen, 2021; Advances in Political Psychology***********************
************* Candidate Evaluations through the Lens of Adaptive Followership Psychology **********
***************************************************************************************************

*************************** Recodings of used variables *******************************************
*** Excludes subjects based on failed attention check
tab Q9
drop if Q9 !=-99

*** Context variable
generate context =.
replace context = 1 if Q14 !=.
replace context = 1 if Q16 !=.
replace context = 1 if Q18 !=.
replace context = 1 if Q20 !=.
replace context = 0 if Q22 !=.
replace context = 0 if Q24 !=.
replace context = 0 if Q26 !=.
replace context = 0 if Q28 !=.
label define contextLB 0 "Hurricane" 1 "Pirates" 
label values context contextLB


*** Manipulation check
clonevar Mani_Check = Q35
label define Mani_CheckLB 1 "Pirates" 2 "Hurricane/Bad weather" 3 "Something else"
label values Mani_Check Mani_CheckLB

* Creates variable for correct recall of context
generate correct_recall =.
replace correct_recall = 1 if context == 1 & Mani_Check == 1
replace correct_recall = 1 if context == 0 & Mani_Check == 2
replace correct_recall = 0 if context == 1 & Mani_Check == 2
replace correct_recall = 0 if context == 1 & Mani_Check == 3
replace correct_recall = 0 if context == 0 & Mani_Check == 1
replace correct_recall = 0 if context == 0 & Mani_Check == 3

tab correct_recall


*** Order of choices
generate order =.
replace order = 1 if Q14 !=.
replace order = 1 if Q16 !=.
replace order = 0 if Q18 !=.
replace order = 0 if Q20 !=.
replace order = 1 if Q22 !=.
replace order = 1 if Q24 !=.
replace order = 0 if Q26 !=.
replace order = 0 if Q28 !=.
label define orderLB 0 "buddy first, captain last" 1 "captain first, buddy last" 
label values order orderLB


*** Creates variable for which face (of the two face pairs) were used for captain and cabin mate
gen face_captain=.
replace face_captain = 1 if Q14 !=.
replace face_captain = 2 if Q16 !=.
replace face_captain = 2 if Q19 !=.
replace face_captain = 1 if Q21 !=.
replace face_captain = 1 if Q22 !=.
replace face_captain = 2 if Q24 !=.
replace face_captain = 2 if Q27 !=.
replace face_captain = 1 if Q29 !=.

gen face_cabinmate=.
replace face_cabinmate = 2 if Q15 !=.
replace face_cabinmate = 1 if Q17 !=.
replace face_cabinmate = 1 if Q18 !=.
replace face_cabinmate = 2 if Q20 !=.
replace face_cabinmate = 2 if Q23 !=.
replace face_cabinmate = 1 if Q25 !=.
replace face_cabinmate = 1 if Q26 !=.
replace face_cabinmate = 2 if Q28 !=.



***** Dependent variables
*** Recodes face choice variables such that non-dominant face = 0; dominant face = 1.
recode Q14 - Q29 (2=1) (1=0)

*** Captain choice
egen captain = rowmean(Q14 Q16 Q19 Q21 Q22 Q24 Q27 Q29)

*** Cabin mate
egen cabin_mate = rowmean(Q15 Q17 Q18 Q20 Q23 Q25 Q26 Q28)



***** Individual differences measures
*** Parti identification
generate partyid =.
replace partyid = 1 if Q3 == 2
replace partyid = 2 if Q3 == 1
replace partyid = 3 if Q5 == 1
replace partyid = 4 if Q5 == 3
replace partyid = 5 if Q5 == 2
replace partyid = 6 if Q4 == 1
replace partyid = 7 if Q4 == 2

generate partyID = (partyid-1)/6


*** Political ideology (liberal - conservative 7-point scale)
generate ideology = (Q8-1)/6


*** Social Dominance Orientation
recode Q6_1 Q6_2 Q6_3 Q6_5 (-99=.)
recode Q6_4 Q6_6 Q6_7 Q6_8 (7=1) (6=2) (5=3) (4=4) (3=5) (2=6) (1=7) (-99=.)

alpha Q6_1 Q6_2 Q6_3 Q6_4 Q6_5 Q6_6 Q6_7 Q6_8

egen sdo = rowmean(Q6_1 Q6_2 Q6_3 Q6_4 Q6_5 Q6_6 Q6_7 Q6_8)
generate SDO = (sdo-1)/6


*** Competitive Jungle Worldview
recode Q11_1 Q11_3 Q11_6 Q11_8 (-99=.)
recode Q11_2 Q11_4 Q11_5 Q11_7 (7=1) (6=2) (5=3) (4=4) (3=5) (2=6) (1=7) (-99=.)

alpha Q11_1 Q11_2 Q11_3 Q11_4 Q11_5 Q11_6 Q11_7 Q11_8

egen cjw = rowmean(Q11_1 Q11_2 Q11_3 Q11_4 Q11_5 Q11_6 Q11_7 Q11_8)
generate CJW = (cjw-1)/6


*** Rightwing Authoritarianism
recode Q7_1 Q7_3 Q7_5 Q7_7 (-99=.)
recode Q7_2 Q7_4 Q7_6 Q7_8 (7=1) (6=2) (5=3) (4=4) (3=5) (2=6) (1=7) (-99=.)

alpha Q7_1 Q7_2 Q7_3 Q7_4 Q7_5 Q7_6 Q7_7 Q7_8

egen rwa = rowmean(Q7_1 Q7_2 Q7_3 Q7_4 Q7_5 Q7_6 Q7_7 Q7_8)
generate RWA = (rwa-1)/6


*** The World is a Dangerous Place
recode Q10_1 Q10_4 Q10_6 Q10_8 (-99=.)
recode Q10_2 Q10_3 Q10_5 Q10_7 (7=1) (6=2) (5=3) (4=4) (3=5) (2=6) (1=7) (-99=.)

alpha Q10_1 Q10_2 Q10_3 Q10_4 Q10_5 Q10_6 Q10_7 Q10_8

egen wdp = rowmean(Q10_1 Q10_2 Q10_3 Q10_4 Q10_5 Q10_6 Q10_7 Q10_8)
generate WDP = (wdp-1)/6

*** Background characteristics
* sex
recode Q31 (-99=.), generate(sex)
label define sexLB 1 "Male" 2 "Female" 3 "Other"
label values sex sexLB

* age
recode Q30 (-99=.)
generate age = 2020-Q30

* education
recode Q32 (-99=.), generate(education)
label define eduLB 1 "Less than high school" 2 "High school graduate" 3 "Some college, but no degree" 4 "2 year degree" 5 "4 year degree" 6 "Professional degree" 7 "Doctorate"
label values education eduLB

* Income
recode Q34 (-99=.)
generate income = (Q34-1)/10
summ income

* Religiosity
recode Q33 (-99=.), generate(religiosity)
label define relLB 1 "Not at all religious" 2 "A little religious" 3 "Rather religious" 4 "Very religious" 5 "Can't say"
label values religiosity relLB




*************** Results reported for Distinctiveness Prediction, Intergroup Conflict ***********************
***** Descriptive statistics and correlations for individual difference constructs
summ ideology partyID SDO CJW RWA WDP
corr ideology partyID SDO CJW RWA WDP 


*** Experimental effects of intergroup conflict
ttest captain, by(context)
ttest cabin_mate, by(context)

*** Difference between preferred levels of dominance in captain and cabin mate
* Overall
ttest captain == cabin_mate
* In intergroup conflict condition
ttest captain == cabin_mate if context == 1
* In control condition
ttest captain == cabin_mate if context == 0



*** Individual difference effects
logit captain i.context c.ideology i.sex c.age ib(1).education c.income i.religiosity, robust
logit cabin_mate i.context c.ideology i.sex c.age ib(1).education c.income i.religiosity, robust

logit captain i.context c.partyID i.sex c.age ib(1).education c.income i.religiosity, robust
logit cabin_mate i.context c.partyID i.sex c.age ib(1).education c.income i.religiosity, robust

logit captain i.context c.SDO i.sex c.age ib(1).education c.income i.religiosity, robust
logit cabin_mate i.context c.SDO i.sex c.age ib(1).education c.income i.religiosity, robust

logit captain i.context c.CJW i.sex c.age ib(1).education c.income i.religiosity, robust
logit cabin_mate i.context c.CJW i.sex c.age ib(1).education c.income i.religiosity, robust



******************************** Figure 4 in article ********************************************
***** Ideology
** Captain choice analyses (Panel A)
logit captain i.context c.ideology i.sex c.age ib(1).education c.income i.religiosity, robust
margins, at(ideology=(0 (0.1) 1) context=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) xtitle("Liberal-Conservative Ideology") yscale(range(0 1)) ylabel(0(.1)1,nogrid) ///
ytitle("Predicted Probability for" "Choice of Dominant Face") title("Panel A: Choice of Captain") name(Fig4a, replace)

** Cabin mate choice analyses (Panel B)
logit cabin_mate i.context c.ideology i.sex c.age ib(1).education c.income i.religiosity, robust
margins, at(ideology=(0 (0.1) 1) context=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) xtitle("Liberal-Conservative Ideology") yscale(range(0 1)) ylabel(0(.1)1,nogrid) ///
ytitle("Predicted Probability for" "Choice of Dominant Face") title("Panel B: Choice of Cabin Mate") name(Fig4b, replace)


***** Social Dominance Orientation
** Captain choice analyses (Panel C)
logit captain i.context c.SDO i.sex c.age ib(1).education c.income i.religiosity, robust
margins, at(SDO=(0 (0.1) 1) context=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) xtitle("Social Dominance Orientation") yscale(range(0 1)) ylabel(0(.1)1,nogrid) ///
ytitle("Predicted Probability for" "Choice of Dominant Face") title("Panel C: Choice of Captain") name(Fig4c, replace)

** Cabin mate choice analyses (Panel D)
logit cabin_mate i.context c.SDO i.sex c.age ib(1).education c.income i.religiosity, robust
margins, at(SDO=(0 (0.1) 1) context=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) xtitle("Social Dominance Orientation") yscale(range(0 1)) ylabel(0(.1)1,nogrid) ///
ytitle("Predicted Probability for" "Choice of Dominant Face") title("Panel D: Choice of Cabin Mate") name(Fig4d, replace)

graph combine Fig4a Fig4b Fig4c Fig4d, col(2)


******************************** Table S.3.1 in Supplementary Materials ********************************************
** Captain choice analyses (Model A)
logit captain i.context c.ideology i.sex c.age ib(1).education c.income i.religiosity, robust
** Cabin mate choice analyses (Model B)
logit cabin_mate i.context c.ideology i.sex c.age ib(1).education c.income i.religiosity, robust
** Captain choice analyses (Model C)
logit captain i.context c.SDO i.sex c.age ib(1).education c.income i.religiosity, robust
** Cabin mate choice analyses (Model D)
logit cabin_mate i.context c.SDO i.sex c.age ib(1).education c.income i.religiosity, robust


******************************** Table S.3.2 in Supplementary Materials ********************************************
** Captain choice analyses (Model A)
logit captain i.context c.partyID i.sex c.age ib(1).education c.income i.religiosity, robust
** Cabin mate choice analyses (Model B)
logit cabin_mate i.context c.partyID i.sex c.age ib(1).education c.income i.religiosity, robust
** Captain choice analyses (Model C)
logit captain i.context c.CJW i.sex c.age ib(1).education c.income i.religiosity, robust
** Cabin mate choice analyses (Model D)
logit cabin_mate i.context c.CJW i.sex c.age ib(1).education c.income i.religiosity, robust


******************************** Figure S.3.1 in Supplementary Materials ********************************************
***** Party Identification
** Captain choice analyses (Panel A)
logit captain i.context c.partyID i.sex c.age ib(1).education c.income i.religiosity, robust
margins, at(partyID=(0 (0.1) 1) context=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) xtitle("Democrat-Republican party identification") yscale(range(0 1)) ylabel(0(.1)1,nogrid) ///
ytitle("Predicted Probability for" "Choice of Dominant Face") title("Panel A: Choice of Captain") name(FigS3_1_a, replace)

** Cabin mate choice analyses (Panel B)
logit cabin_mate i.context c.partyID i.sex c.age ib(1).education c.income i.religiosity, robust
margins, at(partyID=(0 (0.1) 1) context=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) xtitle("Democrat-Republican party identification") yscale(range(0 1)) ylabel(0(.1)1,nogrid) ///
ytitle("Predicted Probability for" "Choice of Dominant Face") title("Panel B: Choice of Cabin Mate") name(FigS3_1_b, replace)


***** Competitive Jungle Worldview
** Captain choice analyses (Panel C)
logit captain i.context c.CJW i.sex c.age ib(1).education c.income i.religiosity, robust
margins, at(CJW=(0 (0.1) 1) context=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) xtitle("Competitive Jungle Worldview") yscale(range(0 1)) ylabel(0(.1)1,nogrid) ///
ytitle("Predicted Probability for" "Choice of Dominant Face") title("Panel C: Choice of Captain") name(FigS3_1_c, replace)

** Cabin mate choice analyses (Panel D)
logit cabin_mate i.context c.CJW i.sex c.age ib(1).education c.income i.religiosity, robust
margins, at(CJW=(0 (0.1) 1) context=(0 1))
marginsplot, recastci(rline) ciopts(lpattern(dash)) recast(line) yline(0) xtitle("Competitive Jungle Worldview") yscale(range(0 1)) ylabel(0(.1)1,nogrid) ///
ytitle("Predicted Probability for" "Choice of Dominant Face") title("Panel D: Choice of Cabin Mate") name(FigS3_1_d, replace)

graph combine FigS3_1_a FigS3_1_b FigS3_1_c FigS3_1_d, col(2)


********** Reshapes dataset to long format to test differences between captain and cabin mate analyses ***************************
*** Creates variable for choice
clonevar choice2 = captain
clonevar choice1 = cabin_mate

*** reshapes command; variable "type" indicates type of choice (captain (2) or cabin mate (1))
reshape long choice, i(ID) j(type)

label define typeLB 1 "cabin mate" 2 "captain" 
label values type typeLB

** Context effects only
logit choice i.context, cluster(ID)
logit choice i.context i.type, cluster(ID)
logit choice i.context##i.type, cluster(ID)

** Ideology and context
logit choice i.context##i.type c.ideology##i.type i.sex c.age c.education c.income i.religiosity, cluster(ID)

** SDO and context
logit choice i.context##i.type c.SDO##i.type i.sex c.age c.education c.income i.religiosity, cluster(ID)

** CJW and context
logit choice i.context##i.type c.CJW##i.type i.sex c.age c.education c.income i.religiosity, cluster(ID)

** Partisanship and context
logit choice i.context##i.type c.partyID##i.type i.sex c.age c.education c.income i.religiosity, cluster(ID)
